import click
from app import db

def init_db_command(drop):
    """初始化数据库核心逻辑"""
    if drop:
        db.drop_all()
    db.create_all()
    click.echo("Database initialized successfully!")

def register_init_db(app):
    """注册 init-db 命令"""
    @app.cli.command("init-db")
    @click.option("--drop", is_flag=True, help="Delete existing tables first.")
    def init_db(drop):
        """Initialize the database."""
        init_db_command(drop)